﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace CNKI.TPI.Web.Search.Model
{

    public enum SearchMatchType
    { 
        And = 0,
        Or = 1,
    };

    public enum ConditionType
    {
        Eq = 0,
        Ne = 1,
        Like = 2,
        GreaterThan = 3,
        GreaterThanOrEqual = 4,
        LessThan = 5,
        LessThanOrEqual = 6
    };

    [DataContract]
    public class SearchQuery
    {
        [DataMember]
        public SearchMatchType Type { set; get; }
        [DataMember]
        public ConditionType ConditionType { set; get; }
        [DataMember]
        public string Text { set; get; }
        [DataMember]
        public string Key { set; get; }

        public SearchQuery()
        {
        }
        public SearchQuery(string key, string text)
        {
            this.Type = SearchMatchType.And;
            this.ConditionType = ConditionType.Eq;
            this.Key = key;
            this.Text = text;
        }

        public SearchQuery(string key, string text, ConditionType conditionType)
        {
            this.Type = SearchMatchType.And;
            this.ConditionType = conditionType;
            this.Key = key;
            this.Text = text;
        }
        [JsonConstructor]
        public SearchQuery(string key, string text, ConditionType conditionType, SearchMatchType type)
        {
            this.ConditionType = conditionType;
            this.Key = key;
            this.Text = text;
            this.Type = type;
        }

        public SearchQuery(SearchMatchType type, string key, string text)
        {
            this.Type = type;
            this.Key = key;
            this.Text = text;
        }
    }
}
